<%@page import="com.liferay.portal.theme.PortletDisplay"%>
<%@page import="com.library.slayer.model.impl.BookImpl"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ include file="/html/library/init.jsp" %>

<script language="javascript">

	function <portlet:namespace/>saveBook(frm) {
		var bookTitle = frm.<portlet:namespace/>bookTitle.value;
		var author = frm.<portlet:namespace/>author.value;
		
		var params = 
			{
				bookTitle: bookTitle, 
				author: author
			};
		
		var A = AUI();
		A.use('aui-io-request', function(aui) {
			Liferay.Service.library.Book.create(params);
		});
		
		frm.<portlet:namespace/>bookTitle.value = '';
		frm.<portlet:namespace/>author.value = '';
	}
</script>

This is the form to Add/Edit book

<%
	PortletURL saveBookURL = renderResponse.createActionURL();
	long bookId = ParamUtil.getLong(request, "bookId");

	Book book = new BookImpl();
	if (bookId > 0l) {
		book = BookLocalServiceUtil.getBook(bookId);
		saveBookURL.setParameter(ActionRequest.ACTION_NAME, "updateBook");
	} else {
		saveBookURL.setParameter(ActionRequest.ACTION_NAME, "addBook");
	}
%>

<aui:form action="<%= saveBookURL.toString() %>" name="fm" method="POST">
	<aui:input type="hidden" name="redirectURL" value="<%= renderResponse.createRenderURL().toString() %>"/>
	<c:if test="<%= bookId > 0l %>">
		<aui:input type="hidden" name="bookId" value="<%= book.getBookId() %>"/>
	</c:if>	
	<aui:input name="bookTitle" label="Book Title" bean="<%= book %>" field="bookTitle" model="<%= Book.class %>" />
	<aui:input name="author" bean="<%= book %>" field="author" model="<%= Book.class %>" />
	
	<liferay-ui:input-permissions modelName="<%= Book.class.getName() %>"/>
	
	<aui:button type="submit" value="Save" />
	<input type="button" value="Save thru JSON &raquo;" onClick="javascript:<portlet:namespace/>saveBook(this.form);" />
</aui:form>

<br/><a href="<portlet:renderURL/>">&laquo; Go Back</a>